  import {
      getRoleList
  } from './models/getRoleList.model';
  import {
      editView
  } from './views/edit.view';
  import {
      editValidate
  } from './editValidate';
  import {
      submit
  } from './submit';
    import {
      msg,modal7
  } from '../common/layer';

  const editBtnHandler = () => {

      let selectedList = $('#table').bootstrapTable('getSelections');
      if (selectedList.length === 0) {
          msg('请选择一项编辑');
          return;
      }

      const localData = selectedList[0];

      getRoleList(localData.roleid, function (data) {

          modal7('编辑', editView(localData, data));

          $(".modal-form input").iCheck({
              checkboxClass: 'icheckbox_minimal-blue',
              radioClass: 'iradio_minimal-blue'
          });

          $('#submitBtn').click(() => {
              let data = {};
              $.each($('#form').serializeArray(), (key, val) => {
                  data[val.name] = val.value;
              });
              let roleid = $('#rolelist .checked input').val();
              data.roleid = roleid;

              if (!editValidate(data)) {
                  return;
              }

              data.id = localData.id;
              submit(GLOBAL_adminEditUrl, data);
          });



      });



  };


  export {
      editBtnHandler
  }